package com.bd.wechat.controller.admin;


import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bd.wechat.core.R;
import com.bd.wechat.entity.ShopFranchise;
import com.bd.wechat.entity.request.FranchiseApplyForRequest;
import com.bd.wechat.entity.request.FranchiseApproveRequest;
import com.bd.wechat.entity.request.MyRecordFranchisePageRequest;
import com.bd.wechat.entity.request.ShopFranchisePageRequest;
import com.bd.wechat.entity.response.ShopFranchiseDetailResponse;
import com.bd.wechat.entity.response.ShopFranchiseMyRecordResponse;
import com.bd.wechat.service.ShopFranchiseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author linhs
 * @menu 小程序端
 * @since 2024-11-15
 */
@RestController
@RequestMapping("/wechat/admin/franchise")
@Slf4j
public class AdminShopFranchiseController {

    @Resource
    private ShopFranchiseService shopFranchiseService;

    /**
     * 加盟申请分页
     *
     * @param pageRequest
     * @return
     */
    @CrossOrigin
    @GetMapping("/page/{pageNum}/{pageSize}")
    public R<Page<ShopFranchise>> page(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize,
            @RequestBody(required = false) ShopFranchisePageRequest pageRequest) {

        log.info("加盟申请分页,start:{},end:{},参数：{}", pageNum, pageSize, JSON.toJSONString(pageRequest));

        Page<ShopFranchise> page = shopFranchiseService.pageShopFranchise(pageNum, pageSize, pageRequest);
        return R.ok(page);
    }

    /**
     * 加盟申请详情
     *
     * @param franchiseId
     * @return
     */
    @CrossOrigin
    @GetMapping("/detail/{franchiseId}")
    public R<ShopFranchiseDetailResponse> detail(@PathVariable("franchiseId") Long franchiseId) {

        log.info("加盟申请详情,参数franchiseId：{}",franchiseId);

        ShopFranchiseDetailResponse detail = shopFranchiseService.detail(franchiseId);
        return R.ok(detail);
    }


    /**
     * 审批
     *
     * @param request
     * @return
     */
    @PostMapping("/approve")
    public R approve(@RequestBody FranchiseApproveRequest request) {

        log.info("加盟申请审批：{}", JSON.toJSONString(request));

        shopFranchiseService.approve(request);
        return R.ok();
    }


}

